package com.net.shop.car.manager.api.volley.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.ShareRule;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.LogUtils;
import com.net.shop.car.manager.utils.StringUtils;

public class ShareRuleListResponse extends Response {
	
	/**
	 * 
	 */
	private List<ShareRule> rules;

	public ShareRuleListResponse() {
		super(Constants.SHARE_YOULI);
	}
	
	@Override
	public String getContentTag() {
		// TODO Auto-generated method stub
		return "share";
	}
	
	@Override
	public void parseContent(String content) {
		try {
			rules = new ArrayList<ShareRule>();
			JSONArray jsonArray = new JSONArray(content);
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject = jsonArray.getJSONObject(i);
				ShareRule shareRule = new ShareRule();
				shareRule.setShareName(StringUtils.filterNull(jsonObject.getString("SHARE_NAME")));
				shareRule.setShareType(StringUtils.filterNull(jsonObject.getString("SHARE_TYPE")));
				shareRule.setShareVB(StringUtils.filterNull(jsonObject.getString("SHARE_VB")));
				rules.add(shareRule);
			}
		} catch (JSONException e) {
			LogUtils.e(e.getMessage());
		}
	}

	/**
	 * @return the rules
	 */
	public List<ShareRule> getRules() {
		return rules;
	}
}
